package com.carleasoft.mps.cms.business.article.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.annotation.OpImgAnnotation;
import com.carleasoft.mps.cms.annotation.OpenApi;
import com.carleasoft.mps.cms.business.article.bean.po.CategoryPo;
import com.carleasoft.mps.cms.business.article.bean.vo.ArticleVo;
import com.carleasoft.mps.cms.business.article.service.ArticleService;
import com.carleasoft.mps.cms.business.article.service.CategoryService;
import com.carleasoft.mps.cms.business.article.bean.po.ArticlePo;
import com.carleasoft.mps.cms.business.article.bean.vo.CategoryNameTreeVo;
import com.carleasoft.mps.cms.business.article.bean.vo.EipIndexOf;
import com.carleasoft.mps.cms.business.article.bean.vo.SlideshowEIPVo;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.PageResult;
import com.carleasoft.mps.data.mybatisplus.page.Pagehelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>Description: EIPArticleController</p>
 * @since 2021/7/5
 * @author
 */
@RestController
@RequestMapping("/eip")
public class EIPArticleController {


    @Autowired
    private ArticleService articleService;

    @Autowired
    private CategoryService categoryService;
    /**
     * 获取信息列表,分页
     * @param articlePo
     * @return ResultBody
     */
    @PostMapping("/eipPageQuery")
    @OpImgAnnotation("imagePath")
    public R eipPageQuery(@RequestBody ArticlePo articlePo, HttpServletRequest request) {
        Page<SlideshowEIPVo> results = articleService.EIPPageQuery(new Page(articlePo.getCurrent(),articlePo.getSize()), articlePo);
        return R.ok(results);
    }

    /**
     * 根据文章编码查询上下篇
     * @param articlePo
     * @return
     */
    @PostMapping("/eipUpAndDown")
    @OpImgAnnotation("imagePath")
    public  R eipUpAndDown(@RequestBody ArticlePo articlePo){
        Page<ArticlePo> page = new Pagehelper(articlePo);
        EipIndexOf results = articleService.eipUpAndDown(page,articlePo);
        return R.ok(results);
    }

    /**
     * 分页查询头条信息
     */
    @PostMapping("/topPageQuery")
    @OpImgAnnotation("imagePath")
    public R topPageQuery(@RequestBody ArticlePo articlePo,Page page){
        page= articleService.topPageQuery(page, articlePo);
        return R.ok(page);
    }

    /**
     *门户首页查询
     * @param categoryCode
     * @return
     */
    @GetMapping("/homePage/{categoryCode}")
    @Deprecated
    public R homePage(@PathVariable String categoryCode){
        return R.ok(articleService.homePage(categoryCode));
    }

    /**
     *
     * @param categoryCode
     * @return
     */
    @GetMapping("/slideshowPage/{categoryCode}")
    @Deprecated
    public R slideshowPage(@PathVariable String categoryCode){
        return R.ok(articleService.slideshowPage(categoryCode));
    }

    /**
     * 详情查询
     * @param articleCode
     * @return
     */
    @GetMapping("/eipArticleDetail")
    @OpImgAnnotation("imagePath")
    public R findByIdArticle(@RequestParam("articleCode") String articleCode) {
        ArticleVo detailVo = articleService.findByIdArticle(articleCode,"eip");
        return R.ok(detailVo);
    }

    /**
     * 树接口查询
     */
    @PostMapping("/category/tree")
    public R categoryTree(@RequestBody CategoryPo categoryPo) {
        List<CategoryNameTreeVo> allCategory = categoryService.categoryTree(categoryPo);
        return  R.ok(allCategory);
    }

}
